package com.hereway.core.context;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页使用的对象
 * 
 * @author Kevin.H   
 *@version 1.0
 *@Team KapnoDM
 */
public class PageBean { 
	private int perPage = 10;// Records per page;
	private long total = 0;// Total record;
	private int index = 1;// The page num which is loaded from,one based;
	private long pageCount = 0;
	private List<String> pageList;
	private int upNo;       
	private int nextNo;   

	public void setIndex(int index) {
		this.index = index;
	}

	public int getPerPage() {
		return perPage;
	}

	public void setPerPage(int perPage) {
		this.perPage = perPage;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}
 
	public int getStart() {
		int startNum = Long.valueOf(this.getPageCount()).intValue();
		if(index>startNum){
			index = startNum; 
		}
		return (index - 1) * perPage;
	}

	public int getIndex() {
		return index;
	}

	public long getPageCount() {
		if (total % perPage == 0) {
			pageCount = total / perPage;
		} else {
			pageCount = total / perPage + 1;
		}

		return pageCount;
	}

	public int getNextNo() {
		if (this.pageCount == this.index) {
			nextNo = this.index;
		} else {
			nextNo = this.index + 1;
		}
		return nextNo;
	}

	public int getUpNo() {
		if (this.index == 1) {
			upNo = 1;
		} else {
			upNo = this.index - 1;
		}
		return upNo;
	}

	public List<String> getPageList() {
		pageList = new ArrayList<String>();
		for (int i = 1; i <= this.pageCount; i++) {
			pageList.add(String.valueOf(i));
		}
		return pageList;
	}

}
